{{#if (or (neq apiEntity.entity.storage "NONE")(apiEntity.entity.virtualMulINHDE))}}
package {{packageName}}.{{apis}}.rest;

import java.util.*;
{{#if entity.hasBigDecimal}}
import java.math.BigDecimal;
{{/if}}
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.ApiOperation;
import cn.ibizlab.util.domain.ImportResult;
import {{packageName}}.{{apis}}.dto.*;
import {{packageName}}.{{apis}}.mapping.*;
import {{packageName}}.core.{{apiEntity.entity.module}}.domain.{{apiEntity.entity.codeName}};
import {{packageName}}.core.{{apiEntity.entity.module}}.service.{{apiEntity.entity.codeName}}Service;
import {{packageName}}.core.{{apiEntity.entity.module}}.filter.{{apiEntity.entity.codeName}}SearchContext;
{{#if apiEntity.entity.lastModifyField}}
import cn.ibizlab.util.annotation.VersionCheck;
{{/if}}

/**
 * 实体[{{apiEntity.codeName}}] rest实现
 *
 * @author generator
 */
@Slf4j
public abstract class Abstract{{apiEntity.codeName}}Resource {

    @Autowired
    public {{apiEntity.entity.codeName}}Service {{camelCase apiEntity.entity.codeName}}Service;

{{#each apiEntity.dtos}}
    {{#or (eq type "DEFAULT")(eq type "DEFILTER")}}
    @Autowired
    @Lazy
    public {{codeName}}Mapping {{camelCase codeName}}Mapping;

    {{/or}}
{{/each}}

{{#each apiEntity.methods}}
{{#neq name "Select"}}
    /**
    * {{apiName}} {{tags}}
    * {{#if psDEAction}}{{psDEAction.memo}}{{/if}}{{#if psDEDataSet}}{{psDEDataSet.memo}}{{/if}}
    *
    {{#each pathVariables}}
    * @param {{camelCase name}} {{camelCase name}}
    {{/each}}
    {{#if body}}
    * @param {{inParamName}} {{inParamName}}
    {{/if}}
    * @return ResponseEntity<{{outParam}}>
    */
    @ApiOperation(value = "{{apiName}}", tags = {"{{tags}}" },  notes = "{{notes}} {{#if psDEAction}}{{replaceWrap psDEAction.memo}}{{/if}}{{#if psDEDataSet}}{{replaceWrap psDEDataSet.memo}}{{/if}}")
    {{#if permission}}
    @{{permission.ano}}("{{permission.cond3}}")
    {{/if}}
    {{#eq methodType "DEACTION"}}
        {{#eq name "Update"}}
            {{#if apiEntity.entity.lastModifyField}}
    @VersionCheck(entity = "{{lowerCase apiEntity.entity.codeName}}" , versionfield = "{{camelCase apiEntity.entity.lastModifyField.codeName}}")
            {{/if}}
            {{#eq requestMethod "POST"}}
    @PutMapping("{{replace requestPath2 '{id}/update' '{id}'}}")
            {{/eq}}
        {{/eq}}
        {{#eq name "Remove"}}
            {{#eq requestMethod "POST"}}
    @DeleteMapping("{{replace requestPath2 '{id}/remove' '{id}'}}")
            {{/eq}}
        {{/eq}}
        {{#eq name "Get"}}
            {{#eq requestMethod "POST"}}
    @GetMapping("{{replace requestPath2 '{id}/get' '{id}'}}")
            {{/eq}}
        {{/eq}}
    {{/eq}}
        {{#eq name "Create"}}
    @PostMapping(value = {"{{replace requestPath2 '/create' ''}}","{{requestPath2}}"})
        {{else}}
    @{{pascalCase requestMethod}}Mapping("{{requestPath2}}")
        {{/eq}}
    public ResponseEntity<{{outParam}}> {{camelCase name}}{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}}
            ({{#each pathVariables}}{{#unless @first}}, {{/unless}}@PathVariable("{{camelCase name}}") {{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}{{#neq requestMethod 'GET'}}@Validated @RequestBody {{else}}@SpringQueryMap {{/neq}}{{replace body "SearchContext" "FilterDTO"}}{{/if}}) {
    {{!行为}}
    {{#eq methodType "DEACTION"}}
        {{#if needDto2Domain}}
        {{inParam2}} {{inParamName2}} = {{camelCase inputDTO.name}}Mapping.toDomain({{inParamName}});
            {{#if listIn}}
                {{#if pathVariables}}
        {{inParamName2}}.forEach(item -> {
                {{#each pathVariables}}{{#if @last}}
            item.set{{pascalCase name}}({{camelCase name}});
                {{/if}}{{/each}}
        });
                {{/if}}
            {{else}}
                {{#each pathVariables}}{{#if @last}}
        {{inParamName2}}.set{{pascalCase name}}({{camelCase name}});
                {{/if}}{{/each}}
            {{/if}}
        {{/if}}
        {{#if booleanReturn}}
        {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{inParamName2}});
        {{outParam2}} rt = {{inParamName2}};
        {{else}}
        {{outParam2}} rt = {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{inParamName2}});
        {{/if}}
        {{#if needDomain2Dto}}
        return ResponseEntity.status(HttpStatus.OK).body({{camelCase returnDTO.name}}Mapping.toDto(rt));
        {{else}}
        return ResponseEntity.status(HttpStatus.OK).body(rt);
        {{/if}}
    {{/eq}}
    {{!数据集}}
    {{#eq methodType "FETCH"}}
        {{#each pathVariables}}
            {{#if @last}}
        {{inParamName}}.set{{pascalCase name}}EQ({{camelCase name}});
            {{/if}}
        {{/each}}
        {{apiEntity.codeName}}SearchContext context = {{camelCase apiEntity.codeName}}FilterDtoMapping.toDomain({{inParamName}});
        Page<{{apiEntity.entity.codeName}}> domains = {{camelCase apiEntity.entity.codeName}}Service.search{{pascalCase pSDEDataSet.codeName}}(context) ;
        {{outParam}} list = {{camelCase returnDTO.name}}Mapping.toDto(domains.getContent());
            return ResponseEntity.status(HttpStatus.OK)
            .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
            .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
            .header("x-total", String.valueOf(domains.getTotalElements()))
            .body(list);
    {{/eq}}
    }

{{#eq name "GetDraft"}}
            {{#eq requestMethod "POST"}}
    @GetMapping("{{requestPath2}}")
    public ResponseEntity<{{outParam}}> {{camelCase name}}2{{#each pathVariables}}{{#if @first}}By{{else}}And{{/if}}{{pascalCase name}}{{/each}}
            ({{#each pathVariables}}{{#unless @first}}, {{/unless}}@PathVariable("{{camelCase name}}") {{type.java}} {{camelCase name}}{{/each}}{{#if body}}{{#if pathVariables}}, {{/if}}@SpringQueryMap {{body}}{{/if}}) {
        {{inParam2}} {{inParamName2}} = {{camelCase inputDTO.name}}Mapping.toDomain({{inParamName}});
                {{#each pathVariables}}{{#if @last}}
        {{inParamName2}}.set{{pascalCase name}}({{camelCase name}});
                {{/if}}{{/each}}
        {{outParam2}} rt = {{camelCase apiEntity.entity.codeName}}Service.{{camelCase name}}({{inParamName2}});
        return ResponseEntity.status(HttpStatus.OK).body({{camelCase returnDTO.name}}Mapping.toDto(rt));
    }
            {{/eq}}
{{/eq}}
{{/neq}}
{{/each}}

{{#each apiEntity.methods}}
{{#unless parentApiEntities}}
    {{#eq name "Create"}}
    /**
    * 批量新建{{apiEntity.entity.logicName}}
    * @param dtos
    * @return ResponseEntity<Boolean>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','{{projectName}}-{{apiEntity.entity.codeName}}-Create-all')")
    @ApiOperation(value = "批量新建{{apiEntity.entity.logicName}}", tags = {"{{apiEntity.entity.logicName}}" },  notes = "批量新建{{apiEntity.entity.logicName}}")
	@{{pascalCase requestMethod}}Mapping("{{pluralize apiEntity.opt.codeName}}/{{#if opt.codeName}}{{lowerCase opt.codeName}}{{/if}}batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<{{apiEntity.defaultDto.codeName}}> dtos) {
        {{camelCase apiEntity.entity.codeName}}Service.createBatch({{camelCase apiEntity.defaultDto.codeName}}Mapping.toDomain(dtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    {{/eq}}
    {{#eq name "Update"}}
    /**
    * 批量更新{{apiEntity.entity.logicName}}
    * @param dtos
    * @return ResponseEntity<Boolean>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','{{projectName}}-{{apiEntity.entity.codeName}}-Update-all')")
    @ApiOperation(value = "批量更新{{apiEntity.entity.logicName}}", tags = {"{{apiEntity.entity.logicName}}" },  notes = "批量更新{{apiEntity.entity.logicName}}")
	@{{pascalCase requestMethod}}Mapping("{{pluralize apiEntity.opt.codeName}}/{{#if opt.codeName}}{{lowerCase opt.codeName}}{{/if}}batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<{{apiEntity.defaultDto.codeName}}> dtos) {
        {{camelCase apiEntity.entity.codeName}}Service.updateBatch({{camelCase apiEntity.defaultDto.codeName}}Mapping.toDomain(dtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    {{/eq}}
    {{#eq name "Save"}}
    /**
    * 批量保存{{apiEntity.entity.logicName}}
    * @param dtos
    * @return ResponseEntity<Boolean>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','{{projectName}}-{{apiEntity.entity.codeName}}-Save-all')")
    @ApiOperation(value = "批量保存{{apiEntity.entity.logicName}}", tags = {"{{apiEntity.entity.logicName}}" },  notes = "批量保存{{apiEntity.entity.logicName}}")
	@PostMapping("{{pluralize apiEntity.opt.codeName}}/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<{{apiEntity.defaultDto.codeName}}> dtos) {
        {{camelCase apiEntity.entity.codeName}}Service.saveBatch({{camelCase apiEntity.defaultDto.codeName}}Mapping.toDomain(dtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    {{/eq}}
    {{#eq name "Save"}}
    /**
    * 批量导入{{apiEntity.entity.logicName}}
    * @param config 导入模式
    * @param ignoreError 导入中忽略错误
    * @return ResponseEntity<ImportResult>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','{{projectName}}-{{apiEntity.entity.codeName}}-Save-all')")
    @ApiOperation(value = "批量导入{{apiEntity.entity.logicName}}", tags = {"{{apiEntity.entity.logicName}}" },  notes = "批量导入{{apiEntity.entity.logicName}}")
	@PostMapping("{{pluralize apiEntity.opt.codeName}}/import")
    public ResponseEntity<ImportResult> importData(@RequestParam(value = "config" , required = false) String config ,@RequestParam(value = "ignoreerror", required = false, defaultValue = "true") Boolean ignoreError ,@RequestBody List<{{apiEntity.defaultDto.codeName}}> dtos) {
        return  ResponseEntity.status(HttpStatus.OK).body({{camelCase apiEntity.entity.codeName}}Service.importData(config,ignoreError,{{camelCase apiEntity.defaultDto.codeName}}Mapping.toDomain(dtos)));
    }

    {{/eq}}
    {{#eq name "Remove"}}
    /**
    * 批量删除{{apiEntity.entity.logicName}}
    * @param ids ids
    * @return ResponseEntity<Boolean>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','{{projectName}}-{{apiEntity.entity.codeName}}-Remove-all')")
    @ApiOperation(value = "批量删除{{apiEntity.entity.logicName}}", tags = {"{{apiEntity.entity.logicName}}" },  notes = "批量删除{{apiEntity.entity.logicName}}")
	@{{pascalCase requestMethod}}Mapping("{{pluralize apiEntity.opt.codeName}}/{{#if opt.codeName}}{{lowerCase opt.codeName}}{{/if}}batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<{{apiEntity.entity.keyField.type.java}}> ids) {
        {{camelCase apiEntity.entity.codeName}}Service.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    {{/eq}}
    {{/unless}}
{{/each}}
}
{{/if}}